package com._520it.crm.web.controller;

import com._520it.crm.page.AjaxResult;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.ClientQueryObject;
import com._520it.crm.service.IClientService;
import com._520it.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/clientResourcePool")
public class ClientResourcePoolController {
	@Autowired
	IClientService clientService;

	@RequiresPermissions("clientResourcePool:index")
	@PermissionName("客户资源池列表")
	@RequestMapping("")
	public String index(){
		return "clientResourcePool";
	}

	@RequiresPermissions("clientResourcePool:list")
	@PermissionName("客户资源池数据")
	@RequestMapping("/list")
	@ResponseBody
	public PageResult list(ClientQueryObject qo){
		PageResult pageResult = null;
		qo.setManagerId(null);
		pageResult = clientService.queryPage(qo);
		return pageResult;
	}

	@RequiresPermissions("client:acquire")
	@PermissionName("客户资源池保存")
	@RequestMapping("/acquire")
	@ResponseBody
	public AjaxResult getClient(Long clientId){
		AjaxResult result = null;
		try{
			clientService.acquire(clientId);
			result = new AjaxResult(true,"操作成功");
		}catch(Exception e){
			e.printStackTrace();
			result = new AjaxResult("操作失败,请联系管理员！");
		}
		return result;
	}
}
